<template>
  <div>
    <!--修改弹出框-->
    <!--修改弹出框-->
    <div>
      <!--弹窗-->
      <el-dialog width="65%" title="信息修改" :visible.sync="dialogFormVisible">
        <el-form  :model="formupd" label-width="100px">
          <el-alert class="title" :closable="false" title="一、讲师基本信息" type="info" />
          <br/>
          <el-row>
            <el-col :span="12"><div>
              <el-form-item label="用户手机：">
                <el-input :disabled="true" v-model="formupd.tPhone"></el-input>
              </el-form-item>
            </div></el-col>
            <el-col :span="12"><div>
              <el-form-item label="讲师名称：">
                <el-input v-model="formupd.tName"></el-input>
              </el-form-item>
            </div></el-col>
          </el-row>
          <el-row>
            <el-col :span="12"><div>
              <el-form-item label="邮箱：">
                <el-input v-model="formupd.tEmail"></el-input>
              </el-form-item>
            </div></el-col>
          </el-row>
          <el-form-item label="讲师简介：">
            <el-input type="textarea" :rows="2"
                      placeholder="请输入内容"
                      v-model="formupd.tJianjie">
            </el-input>
          </el-form-item>
          <el-alert class="title" :closable="false" title="二、讲师分成及银行信息" type="info" />
          <br/>
          <el-row>
            <el-col :span="12"><div>
              <el-form-item label="开户名称：">
                <el-input :disabled="true" v-model="formupd.tName"></el-input>
              </el-form-item>
            </div></el-col>
          </el-row>
          <el-row>
            <el-col :span="12"><div>
              <el-form-item label="银行卡号：">
                <el-input :disabled="true" v-model="formupd.tBankcard"></el-input>
              </el-form-item>
            </div></el-col>
          </el-row>

        </el-form>
        <el-row style="margin-top:17px; ">
          <el-button style="float:right;margin-left:6px;" size="mini" type="danger" plain @click="closee">取 消</el-button>
          <el-button style="float:right" size="mini" type="primary" @click="updteacher('formupd')">确 定</el-button>
        </el-row>
      </el-dialog>
    </div>
    <!--添加弹出框-->
    <el-dialog
      title="添加"
      :visible.sync="dialogVisible"
      width="30%">
      <span>
        <el-form label-width="80px" :model="tableData">
          <el-form-item label="讲师名称">
            <el-input v-model="tableData.teachername"></el-input>
            <el-button v-has="'/user/pc/user/list'" slot="append" icon="el-icon-search" @click="userList()"></el-button>
          </el-form-item>
          <el-form-item label="手机号码">
            <el-input v-model="tableData.phone"></el-input>
          </el-form-item>
         <el-form-item label="邮箱">
            <el-input v-model="tableData.email"></el-input>
          </el-form-item>

</el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm(person)">确 定</el-button>
            </span>
        </span>
    </el-dialog>
    <!--top查询-->
    <el-form :inline="true"  class="demo-form-inline">
      <el-form-item label="讲师名称">
        <el-input v-model="pagess.tname" placeholder="讲师名称"></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="pagess.tphone" placeholder="手机号"></el-input>
      </el-form-item>
      <!--<template>
        <el-select v-model="pagess.status" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </template>-->
      <template>
        <el-select v-model="pagess.status2" placeholder="请选择">
          <el-option
            v-for="item in shen"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </template>
      <el-form-item>

        <el-button type="primary" @click="se()">查询</el-button>
        <el-button @click="cz()">重置</el-button>

      </el-form-item>
    </el-form>
    <!--审核弹出框-->
    <div>
      <el-dialog title="审核" :visible.sync="aoligei" width="400px">
        <el-form :model="shenhe">
          <el-form-item label="审核结果：">
            <el-radio-group v-model="shenhe.status">
              <!--              <el-radio  v-for="item in auditss" :key="item.auditid" :label="item.auditname">{{item.auditname}}</el-radio>-->
              <el-radio  :label="1">审核通过</el-radio>
              <el-radio  :label="2">审核不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核意见" >
            <el-input placeholder="系统默认通过" type="textarea" v-model="shenhe.tOpinion"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="aoligei = false">取 消</el-button>
          <el-button type="primary" @click="objectsh()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
    <!--点击手机号-->
    <div>
      <el-dialog width="60%" title="信息查看" :visible.sync="phoneDialogTableVisible" style="margin-top: 2%">
        <el-form :inline="true">
          <el-card >
            <el-divider style="font-weight:bold; background-color:#f4f4f5">讲师个人信息</el-divider>

            <el-row>
              <el-col :span="8"><div>

                <el-form-item label="头像:">
                  <div class="demo-image">
                    <div class="block">
                      <el-image style="width: 100px; height: 100px" :src="gridData.t_image"></el-image>
                    </div>
                  </div>
                </el-form-item>
              </div></el-col>
              <el-col :span="8"><div>
                <el-form-item label="讲师编号:">
                  <span >{{gridData.teacher_num}}</span>
                </el-form-item>
                <br/>
                <el-form-item label="讲师名称:">
                  <span >{{gridData.t_name}}</span>
                </el-form-item>
              </div></el-col>
              <br/><br/><br/><br/>
              <el-col :span="8" v-model="gridData.shenhe"><div>
                <el-form-item label="审核状态:">
                  <template slot-scope="scope">
                    <span v-if="gridData.shenhe == 0">待审核</span>
                    <span v-if="gridData.shenhe == 1">通过</span>
                    <span v-if="gridData.shenhe == 2">禁用</span>
                  </template>
                </el-form-item>
                <br/>
              </div></el-col>

              <el-col :span="8" v-model="gridData.status"><div>

                <el-form-item label="状态:">
                  <template slot-scope="scope">
                    <span v-if="gridData.status == 3">正常</span>
                    <span v-if="gridData.status == 4">禁用</span>
                  </template>
                </el-form-item>
              </div></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"><div>
                <el-form-item label="手机号:">
                  <span >{{gridData.t_phone}}</span>
                </el-form-item>
              </div></el-col>
              <el-col :span="8"><div>
                <el-form-item label="邮箱:">
                  <span >{{gridData.t_email}}</span>
                </el-form-item>
              </div></el-col>

            </el-row>

            <el-row>
              <el-col :span="8"><div>
                <el-form-item label="注册时间:">
                  <span >{{gridData.t_createtime}}</span>
                </el-form-item>
              </div></el-col>

            </el-row>
          </el-card>
          <br/>
          <el-card >
            <el-divider style="font-weight:bold; background-color:#f4f4f5">简介</el-divider>
            <el-form-item v-html="gridData.t_jianjie">
            </el-form-item>
          </el-card>
          <br/>
          <el-card >
            <el-divider style="font-weight:bold; background-color:#f4f4f5">分成情况</el-divider>
            <el-row>
              <el-col :span="8"><div>
                <el-form-item label="讲师分成情况:">
                  <span>{{gridData.t_share}}%</span>
                </el-form-item>
              </div></el-col>
              <el-col :span="8"><div>
                <el-form-item label="累计总收入:">
                  <span>{{gridData.shouru}}元</span>
                </el-form-item>
              </div></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"><div>
                <el-form-item label="已提现金额:">
                  <span >{{gridData.use_withdrawn}}元</span>
                </el-form-item>
              </div></el-col>
              <el-col :span="8"><div>
                <el-form-item label="可提现金额:">
                  <span >{{gridData.tixian}}元</span>
                </el-form-item>
              </div></el-col>
              <el-col :span="8"><div>
                <el-form-item label="冻结金额:">
                  <span >{{gridData.dongjie}}元</span>
                </el-form-item>
              </div></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"><div>
                <el-form-item label="银行卡号:">
                  <span >{{gridData.t_bankcard}}</span>
                </el-form-item>
              </div></el-col>
            </el-row>
            <el-row>
              <el-col :span="8"><div>
                <el-form-item label="开户姓名:">
                  <span >{{gridData.t_name}}</span>
                </el-form-item>
              </div></el-col>
              <el-col :span="8"><div>
                <el-form-item label="身份证号:">
                  <span >{{gridData.t_idcard}}</span>
                </el-form-item>
              </div></el-col>
            </el-row>
          </el-card>
        </el-form>
        <el-row style="margin-top:17px; ">
          <el-button style="float:right;margin-left:6px;" size="mini" type="danger" plain @click="phoneDialogTableVisible=false">取 消</el-button>
        </el-row>
      </el-dialog>
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="tid"
        label="序号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="t_phone"
        label="手机号"
        width="180">
        <template labl="tphone" slot-scope="scope">
          <el-button type="text" @click="phonecha(scope.row)">{{scope.row.t_phone}}</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="t_name"
        label="讲师名称">
      </el-table-column>
      <el-table-column
        prop="t_email"
        label="邮箱">
      </el-table-column>
      <el-table-column
        prop="t_share"
        label="分成比例">
        <template labl="tphone" slot-scope="scope">
          <el-button type="text">{{scope.row.t_share}}%</el-button>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.statusid"
            @change="handleChangeStatus(scope.row.id, scope.row.statusid)"
            :active-value="0"
            :inactive-value="1"
            active-color="#ff4949"
            inactive-color="#13ce66"
            active-text="禁用"
            inactive-text="正常">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column
        prop="status2"
        label="审核状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status2 == 0">待审核</span>
          <span v-if="scope.row.status2 == 1">通过</span>
          <span v-if="scope.row.status2 == 2">未通过</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="address"
        label="操作">
        <template slot-scope="scope">
        <el-button type="primary" icon="el-icon-edit" size="small" @click="upd(scope.row)">修改</el-button>
        <el-button type="primary" size="small" @click="shenqq(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagess.currentPage"
      :page-sizes="[2,4,6,8]"
      :page-size="pagess.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pagess.total">
    </el-pagination>
  </div>
</template>

<style>
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>

<script>
  import qs from  'qs'
  export default {
    methods: {
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      },
      //添加
      addte(){
        this.dialogVisible=true;
      },
      //修改按钮状态
      handleChangeStatus(id, statusid) {
        const title = { 0: '禁用', 1: '启用' }
        this.$confirm(`确定要${title[statusid]}吗?`, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          //this.ctrl.load = true;
          //this.changeStatus(id,status)
          //this.reload()
        }).catch(() => {

          //this.reload()
        })
      },
      changeStatus(id, zhuangtai) {
        api.userExtUpdate({id: id, statusId: zhuangtai}).then(res => {
          this.ctrl.load = false
          if (res.code === 200 && res.data > 0) {
            const msg = {0: '禁用成功', 1: '启用成功'}
            this.$message({
              type: 'success',
              message: msg[statusId]
            });
            this.reload()
          } else {
            const msg = {0: '禁用失败', 1: '启用失败'}
            this.$message({
              type: 'error',
              message: msg[statusId]
            });
            this.reload()
          }
        }).catch(() => {
          this.ctrl.load = false
          this.reload()
        })
      },
      /*分页查询*/
      se() {
        this.pagess.currentPage=1;
       this.query()
      },
      /*分页*/
      handleSizeChange(val) {

        this.pagess.pagesize=val;
        this.query()
      },
      handleCurrentChange(val) {

        this.pagess.currentPage=val;
        this.query()
      },
      /*重置*/
      cz() {
        this.pagess.tname=""
        this.pagess.tphone=""
        /*this.pagess.status=""*/
        this.pagess.status2=""
      },
      //查询页面数据
      query(){
       /* this.$axios.get("http://localhost:8061/list/teacher-examine/sele").then(r=>{
          /!*alert(JSON.stringify(r.data))*!/
            this.tableData=r.data;

        })*/
        this.$axios.post("http://localhost:8061/list/teacher-examine/selefenye",qs.stringify(this.pagess)).then(r=>{

          this.tableData=r.data.obj;

        })

          this.$axios.get("http://localhost:8061/list/teacher-examine/setotal").then(r=>{


            this.pagess.total=r.data.obj;
          })


      },
      //修改的取消按钮
      closee(){
        this.dialogFormVisible=false
      },
      //修改按钮
      upd(obj){
        alert(JSON.stringify(obj))
        this.dialogFormVisible=true;
        this.formupd.tid=obj.tid;
        this.formupd.tPhone=obj.t_phone;
        this.formupd.tName=obj.t_name;
        this.formupd.tEmail=obj.t_email;
        this.formupd.tJianjie=obj.t_jianjie;
        this.formupd.tBankcard=obj.t_bankcard;
      },
      //修改弹框确定按钮
      updteacher(formupd){

          if ( !/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,5}$/.test(this.formupd.tName)){
            this.$alert('请输入真实名称', '提示', {
              confirmButtonText: '确定',
            });

          }else if (!/^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(this.formupd.tJianjie)) {
            this.$alert('请输入简介', '提示', {
              confirmButtonText: '确定',
            });
          }else if (!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(this.formupd.tEmail)) {
            this.$alert('请输入邮箱', '提示', {
              confirmButtonText: '确定',
            });
          } else{
            this.$axios.post("http://localhost:8061/list/teacher/upfc",qs.stringify(this.formupd)).then(r=>{
              if (r){
                this.dialogFormVisible=false;
                this.query();
              }
            })



            }
      },
      //审核按钮
      shenqq(obj){
        alert(JSON.stringify(obj))
        if (obj.status2==0){
          this.aoligei=true;
          this.shenhe.status=obj.status2
          this.shenhe.tOpinion=obj.t_opinion;
          this.shenhe.jsId=obj.js_id
          this.updform=obj
          this.sh=obj;
        } else if (obj.status2==1) {
          alert("审核过了臭弟弟")
          this.aoligei=false
        }else {
          alert("审核未通过臭弟弟")
          this.aoligei=false
        }
      },
      //审核中的确定按钮
      objectsh(updform){

          //alert(JSON.stringify(this.shenhe.status))
          this.$axios.post("http://localhost:8061/list/teacher-examine/updyyy",qs.stringify(this.shenhe)).then(r=>{
            if (r){
              this.aoligei=false;
              this.query();
            }
          })
      },
      //点击手机号时查询数据
      phonecha(obj){
        alert(JSON.stringify(obj.tid));
        this.phoneDialogTableVisible=true;
        this.$axios.get("http://localhost:8061/list/teacher-examine/selephone?tid="+obj.tid).then(r=>{
          // alert(JSON.stringify(r.data.obj))
          // this.gridData=r.data.obj
          r.data.obj.forEach(r=>{
            this.gridData=r
          })
        })
        /*this.$axios.get("http://localhost:8061/list/share/selec?tid="+obj).then(r=>{
          r.data.forEach(r=>{
            alert(JSON.stringify(r))
            this.gridData=r;
          })
        })*/
      },

    },
      created(){
      this.query();
      },
    data() {
      return {
        tableData: [],
        gridData:{
          status:"",
          shenhe:"",
          t_share:''
        },
        options:[{
          value:3,
          label:"正常"
        },{
          value:4,
          label:"禁用"
        }
        ],
        shen:[{
          value:0,
          label:"待审核"
        },{
          value:1,
          label:"通过"
        },{
          value:2,
          label:"不通过"
        }],
        form:{
          tOpinion:"",
          status2:"",
        },
        sh:{
          status:""
        },
        updform:{
          status:""
        },
        shenhe:{
          tOpinion:"",
          status:"",
          js_id:""
        },
        formupd:{
          tid:"",
          tShare:"",
          tPhone:"",
          tName:"",
          tEmail:"",
          tJianjie:"",
          tBankcard:"",
        },
        phoneDialogTableVisible:false,
        aoligei:false,
        dialogFormVisible:false,
        value2: true,
        pagess: {
          currentPage:1,//当前页
          pagesize:2,//每页显示条数
          total:0,//数据的总条数
          tname: "",
          tphone:"",
          status: "",
          status2:"",
        },
        /*分页*/
        currentPage4: 4,

        /*弹出框*/
      dialogVisible:false,
      }
    }
  }
</script>
